package cn.ffcs.uec.staffAndOutStaff.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cn.ffcs.uec.common.util.PermissionUtil;
import cn.ffcs.uec.common.vo.UecBdDefdoc;
import cn.ffcs.uec.common.vo.UecBdPsncl;
import cn.ffcs.uec.staffAndOutStaff.dao.StaffAndOutStaffDao;
import cn.ffcs.uec.staffAndOutStaff.vo.SmallContractUnit;
import cn.ffcs.uec.staffAndOutStaff.vo.StaffAndOutStaff;
import cn.ffcs.uec.staffAndOutStaff.vo.StaffTotalInfo;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.PlatformUtil;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("staffAndOutStaffDao")
@Transactional
public class StaffAndOutStaffDaoImpl extends BaseDaoImpl implements StaffAndOutStaffDao {

    @Override
    public PageInfo queryPageInfoByAllStaffIncumbentsVo(StaffAndOutStaff staffAndOutStaff, String operType,
            int current, int pageSize) {
        String orgName = PermissionUtil.getManagerOrg();
        StringBuilder sb = new StringBuilder(" SELECT * FROM VIEW_ALL_INCUMBENTS T WHERE 1 = 1 ");
        List<Object> params = new ArrayList<Object>();
        // 部门负责人 只查合同制专业序列
        if ("deptLeaderEdit".equals(operType)) {
            sb.append(" AND t.postseries = ? AND t.staffType <> '外包自有制'  AND t.staffType <>'离职'");
            params.add("1001A1100000000006R3");
        } else if ("orgLeaderEdit".equals(operType)) {// 组织负责人 // 只查合同制专业序列和外包(目前外包均为专业序列)            
            sb.append(" AND t.postseries = ? AND  t.staffType <>'离职'");
            params.add("1001A1100000000006R3");
        }else {
        	 sb.append(" AND t.staffType <>'离职'");
        }
        if (null != staffAndOutStaff) {
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getStaffName())) {
                sb.append(" AND T.staffName like ? ");
                params.add("%" + StringEscapeUtils.escapeSql(staffAndOutStaff.getStaffName()) + "%");
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getStaffCode())) {
                sb.append(" AND T.staffCode = ? ");
                params.add(staffAndOutStaff.getStaffCode());
            }
        }
        if (!"区本部".equals(orgName)) {
            sb.append(" AND T.orgName LIKE ? ");
            params.add("%" + StringEscapeUtils.escapeSql(orgName) + "%");
        }
        return this.jdbcFindPageInfo(sb.toString(), params, current, pageSize, StaffAndOutStaff.class);
    }
    
    
    @Override
    public PageInfo queryPageInfoByStaffAndOutStaff(StaffAndOutStaff staffAndOutStaff, int current,
            int pageSize) {
       // String orgName = PermissionUtil.getManagerOrg();
        StringBuilder sb = new StringBuilder(" SELECT * FROM VIEW_SATFF_AND_OUTSATFF T WHERE 1 = 1 ");
        List<Object> params = new ArrayList<Object>();
        String code = PlatformUtil.getCurrentUser().getScreenName().toUpperCase();
		String orgName ="";
		//String[] orgnamelist= {"呼伦","兴安","通辽","赤峰","锡林","乌兰","乌海"};
		String[] orgnamelist=null;
		String orgNametemp =null;
		if(!StrUtil.isNullOrEmpty(code)) {
			orgNametemp = PermissionUtil.getManagerOrg();
			if(!StrUtil.isNullOrEmpty(orgNametemp)) {
				orgnamelist=orgNametemp.split(",");
			}
			if(orgnamelist != null && orgnamelist.length==1) {
				orgName=orgnamelist[0];
			}
		}
        if (null != staffAndOutStaff) {
        	//这个是虚拟的人员，故直接写死，蒙通服三个人员
			//String code = PlatformUtil.getCurrentUser().getScreenName().toUpperCase();
			//int temp=0;//初始化
			//String[] orgnamelist= {"呼伦","兴安","通辽","赤峰","锡林","乌兰","乌海"};
			/*if("W2019100".equals(code) || "W2019101".equals(code) || "W2019102".equals(code)) {
				temp=1;
				sb.append("AND (T.orgName like ? ");
				params.add(orgnamelist[0]);
				for(int i=1;i<orgnamelist.length-1;i++) {
					sb.append(" OR T.orgName like ? ");
					params.add("%"+orgnamelist[i]+"%");
				}
				sb.append(" OR T.orgName like ? )");
				params.add(orgnamelist[orgnamelist.length-1]);

			}*/
        	
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getStaffName())) {
                sb.append(" AND T.staffName like ? ");
                params.add("%" + StringEscapeUtils.escapeSql(staffAndOutStaff.getStaffName()) + "%");
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getStaffCode())) {
                sb.append(" AND T.staffCode = ? ");
                params.add(staffAndOutStaff.getStaffCode());
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getPkOrg())) {
                sb.append(" AND T.pkOrg = ? ");
                params.add(staffAndOutStaff.getPkOrg());
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getPkDept())) {
                sb.append(" AND T.pkDept = ? ");
                params.add(staffAndOutStaff.getPkDept());
            }
           /* if(!StrUtil.isNullOrEmpty(staffAndOutStaff.getOrgName())) {
            	if(temp==1) {
	            	for(int i=0;i<orgnamelist.length;i++) {
						if(staffAndOutStaff.getOrgName().contains(orgnamelist[i])) {
							temp=2;
							break;
						}
					}
            	}
            	if(temp==0 || temp==2) {
	            	if(staffAndOutStaff.getOrgName().endsWith("*")) {
	            		sb.append(" AND T.orgName like ? ");
	            		params.add("%"+staffAndOutStaff.getOrgName().substring(0, 2)+"%");
	            	}
	            	else {
	            		sb.append(" AND T.orgName = ? ");
	            		params.add(staffAndOutStaff.getOrgName());
	            	}
            	}else {
            		sb.append(" AND 1=2 ");
            	}
            }*/
            if(!StrUtil.isNullOrEmpty(staffAndOutStaff.getDeptName())) {
                sb.append(" AND T.deptName = ? ");
                params.add(staffAndOutStaff.getDeptName());
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getUecBdPsnclList())) {
                List<UecBdPsncl> UecBdPsncls = staffAndOutStaff.getUecBdPsnclList();
                String a = " AND T.staffcatogery in ( ";
                String b = "";
                String c = ")";
                for (UecBdPsncl uecBdPsncl : UecBdPsncls) {
                    String name = uecBdPsncl.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getEndJobDate())) {
                sb.append(" AND (T.endjobdate <= ? or T.endjobdate is null) ");
                params.add(staffAndOutStaff.getEndJobDate());
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getNewPostGradeList())
                    && staffAndOutStaff.getNewPostGradeList().size() > 0) {
                List<UecBdDefdoc> uecBddefdocs = staffAndOutStaff.getNewPostGradeList();
                String a = "AND T.postlevel in ( ";
                String b = "";
                String c = ")";
                for (UecBdDefdoc uecBdDefdoc : uecBddefdocs) {
                    String name = uecBdDefdoc.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getOldPostGradeList())
                    && staffAndOutStaff.getOldPostGradeList().size() > 0) {
                List<UecBdDefdoc> uecBddefdocs = staffAndOutStaff.getOldPostGradeList();
                String a = "AND T.postlevel in ( ";
                String b = "";
                String c = ")";
                for (UecBdDefdoc uecBdDefdoc : uecBddefdocs) {
                    String name = uecBdDefdoc.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getPostGradeList())) {
                List<UecBdDefdoc> uecBddefdocs = staffAndOutStaff.getPostGradeList();
                String a = "AND T.postgrade in ( ";
                String b = "";
                String c = ")";
                for (UecBdDefdoc uecBdDefdoc : uecBddefdocs) {
                    String name = uecBdDefdoc.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
        }
       /* if (!"区本部".equals(orgName)) {
            sb.append(" AND T.orgName LIKE ? ");
            params.add("%" + StringEscapeUtils.escapeSql(orgName) + "%");
        }*/
        if (!"区本部".equals(orgName) && !StrUtil.isNullOrEmpty(orgName)) {
			sb.append(" AND T.ORGNAME LIKE ? ");
			params.add("%" + StringEscapeUtils.escapeSql(orgName) + "%");
		}
			if(orgnamelist !=null && orgnamelist.length>1) {
				sb.append("AND (T.orgName like ? ");
				params.add("%"+orgnamelist[0]+"%");
				for(int i=1;i<orgnamelist.length-1;i++) {
					sb.append(" OR T.orgName like ? ");
					params.add("%"+orgnamelist[i]+"%");
				}
				sb.append(" OR T.orgName like ? )");
				params.add("%"+orgnamelist[orgnamelist.length-1]+"%");
			}
			//用于查询13个组织下的全部人员
			if(!StrUtil.isNullOrEmpty(staffAndOutStaff.getOrgName())) {
			//为了查询带*号组织下的全部人员
			if(staffAndOutStaff.getOrgName().endsWith("*")) {
					sb.append(" AND T.orgName like ? ");
					params.add("%"+staffAndOutStaff.getOrgName().substring(0, 2)+"%");
        	}
        	else {
        		sb.append(" AND T.orgName = ? ");
        		params.add(staffAndOutStaff.getOrgName());
        	}
		}
        return this.jdbcFindPageInfo(sb.toString(), params, current, pageSize, StaffAndOutStaff.class);
    }

    @Override
    public List<Map<String, Object>> getStaffAndOutStaffData(StaffAndOutStaff staffAndOutStaff) {
        //String orgName = PermissionUtil.getManagerOrg();
        List<Object> params = new ArrayList<Object>();
        StringBuffer sb = new StringBuffer();
        sb.append(" SELECT T.STAFFCATOGERY 人员类型,T.STAFFCODE 人员编码,T.STAFFNAME 人员姓名,T.STAFFNUM  身份证号码, "
                + " T.STAFFSEX  性别,T.ORGCODE  组织编码,T.ORGNAME 组织名称,T.DEPTCODE 部门编码,T.DEPTNAME 部门名称, "
                + " T.FATHERORG 上级组织,T.STAFFBIRTH 出生日期,T.STAFFAGE 年龄,T.STAFFDIFF 年龄分段,T.STAFFNATION 民族, "
                + " T.STAFFJOINWORKDATE 参加工作日期,T.STAFFPOLITY 政治面貌,T.STAFFMOBILE 手机号码,T.STAFFEMAIL 电子邮箱, "
                + " T.STAFFTYPE 人员类别,T.STAFFPOSTNAME 岗位名称,T.JOBGLBDEF4 职务名称,T.JOBGLBDEF14 现职时间,T.POSTLEVEL 岗位层级, "
                + " T.JOBGLBDEF8 任现岗位等级时间,T.POSTGRADE  岗位等级,T.GLBDEF3 进入电信时间,T.BESTEDUCATION 最高学历, "
                + " T.BESTGRADE 最高学位,T.ENDDATE 毕业日期,T.SCHOOL 毕业院校,T.MAJOR 专业 "
                + " FROM VIEW_SATFF_AND_OUTSATFF T WHERE 1 = 1 ");
        String code = PlatformUtil.getCurrentUser().getScreenName().toUpperCase();
		String orgName ="";
		//String[] orgnamelist= {"呼伦","兴安","通辽","赤峰","锡林","乌兰","乌海"};
		String[] orgnamelist=null;
		String orgNametemp =null;
		if(!StrUtil.isNullOrEmpty(code)) {
			orgNametemp = PermissionUtil.getManagerOrg();
			orgnamelist=orgNametemp.split(",");
			if(orgnamelist != null && orgnamelist.length==1) {
				orgName=orgnamelist[0];
			}
		}
        if(null != staffAndOutStaff) {
        	
        	//String code = PlatformUtil.getCurrentUser().getScreenName().toUpperCase();
			//int temp=0;//初始化
			//String[] orgnamelist= {"呼伦","兴安","通辽","赤峰","锡林","乌兰","乌海"};
			//("W2019100".equals(code) || "W2019101".equals(code) || "W2019102".equals(code)) {
			//	temp=1;
			/*sb.append("AND (T.orgName like ? ");
				params.add(orgnamelist[0]);
				for(int i=1;i<orgnamelist.length-1;i++) {
					sb.append(" OR T.orgName like ? ");
					params.add("%"+orgnamelist[i]+"%");
				}
				sb.append(" OR T.orgName like ? )");
				params.add(orgnamelist[orgnamelist.length-1]);

			}*/
			//这是之前的，没修改
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getStaffName())) {
                sb.append(" AND T.staffName like ? ");
                params.add("%" + StringEscapeUtils.escapeSql(staffAndOutStaff.getStaffName()) + "%");
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getStaffCode())) {
                sb.append(" AND T.staffCode = ? ");
                params.add(staffAndOutStaff.getStaffCode());
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getPkOrg())) {
                sb.append(" AND T.pkOrg = ? ");
                params.add(staffAndOutStaff.getPkOrg());
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getPkDept())) {
                sb.append(" AND T.pkDept = ? ");
                params.add(staffAndOutStaff.getPkDept());
            }
            /*if(!StrUtil.isNullOrEmpty(staffAndOutStaff.getOrgName())) {
                sb.append(" AND T.orgName = ? ");
                params.add(staffAndOutStaff.getOrgName());
            }
            if(!StrUtil.isNullOrEmpty(staffAndOutStaff.getOrgName())) {
            	if(temp==1) {
	            	for(int i=0;i<orgnamelist.length;i++) {
						if(staffAndOutStaff.getOrgName().contains(orgnamelist[i])) {
							temp=2;
							break;
						}
					}
            	}
            	if(temp==0 || temp==2) {
            	if(staffAndOutStaff.getOrgName().endsWith("*")) {
            		sb.append(" AND T.orgName like ? ");
            		params.add("%"+staffAndOutStaff.getOrgName().substring(0, 2)+"%");
            	}
            	else {
            		sb.append(" AND T.orgName = ? ");
            		params.add(staffAndOutStaff.getOrgName());
            	}
            }else {
        		sb.append(" AND 1=2 ");
        	}
           } 	*/
            if(!StrUtil.isNullOrEmpty(staffAndOutStaff.getDeptName())) {
                sb.append(" AND T.deptName = ? ");
                params.add(staffAndOutStaff.getDeptName());
            } 
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getUecBdPsnclList())) {
                List<UecBdPsncl> UecBdPsncls = staffAndOutStaff.getUecBdPsnclList();
                String a = " AND T.staffcatogery in ( ";
                String b = "";
                String c = ")";
                for (UecBdPsncl uecBdPsncl : UecBdPsncls) {
                    String name = uecBdPsncl.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
            if(!StrUtil.isNullOrEmpty(staffAndOutStaff.getEndJobDate())) {
                sb.append(" AND (T.endjobdate <= ? or T.endjobdate is null) ");
                params.add(staffAndOutStaff.getEndJobDate());
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getNewPostGradeList())
                    && staffAndOutStaff.getNewPostGradeList().size() > 0) {
                List<UecBdDefdoc> uecBddefdocs = staffAndOutStaff.getNewPostGradeList();
                String a = " AND T.postlevel in ( ";
                String b = "";
                String c = ")";
                for (UecBdDefdoc uecBdDefdoc : uecBddefdocs) {
                    String name = uecBdDefdoc.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getOldPostGradeList())
                    && staffAndOutStaff.getOldPostGradeList().size() > 0) {
                List<UecBdDefdoc> uecBddefdocs = staffAndOutStaff.getOldPostGradeList();
                String a = "AND T.postlevel in ( ";
                String b = "";
                String c = ")";
                for (UecBdDefdoc uecBdDefdoc : uecBddefdocs) {
                    String name = uecBdDefdoc.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
            if (!StrUtil.isNullOrEmpty(staffAndOutStaff.getPostGradeList())) {
                List<UecBdDefdoc> uecBddefdocs = staffAndOutStaff.getPostGradeList();
                String a = "AND T.postgrade in ( ";
                String b = "";
                String c = ")";
                for (UecBdDefdoc uecBdDefdoc : uecBddefdocs) {
                    String name = uecBdDefdoc.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
        }
        /*if (!"区本部".equals(orgName)) {
            sb.append(" AND T.orgName LIKE ? ");
            params.add("%" + StringEscapeUtils.escapeSql(orgName) + "%");
        }*/
        if (!"区本部".equals(orgName) && !StrUtil.isNullOrEmpty(orgName)) {
			sb.append(" AND T.ORGNAME LIKE ? ");
			params.add("%" + StringEscapeUtils.escapeSql(orgName) + "%");
		}
			if(orgnamelist !=null && orgnamelist.length>1) {
				sb.append("AND (T.orgName like ? ");
				params.add("%"+orgnamelist[0]+"%");
				for(int i=1;i<orgnamelist.length-1;i++) {
					sb.append(" OR T.orgName like ? ");
					params.add("%"+orgnamelist[i]+"%");
				}
				sb.append(" OR T.orgName like ? )");
				params.add("%"+orgnamelist[orgnamelist.length-1]+"%");
			}
			//用于查询13个组织下的全部人员
			if(!StrUtil.isNullOrEmpty(staffAndOutStaff.getOrgName())) {
			//为了查询带*号组织下的全部人员
			if(staffAndOutStaff.getOrgName().endsWith("*")) {
					sb.append(" AND T.orgName like ? ");
					params.add("%"+staffAndOutStaff.getOrgName().substring(0, 2)+"%");
        	}
        	else {
        		sb.append(" AND T.orgName = ? ");
        		params.add(staffAndOutStaff.getOrgName());
        	}
		}
        return this.getJdbcTemplate().queryForList(sb.toString(), params.toArray());
    }

    @Override
    public String getStaffAndOutStaffNameByPkPsndoc(String pkPsndoc) {
        if (!StrUtil.isEmpty(pkPsndoc)) {
            StringBuilder sb = new StringBuilder(" SELECT * FROM VIEW_SATFF_AND_OUTSATFF T WHERE 1 = 1 ");
            List<Object> params = new ArrayList<Object>();
            sb.append(" AND T.pkPsndoc = ? ");
            params.add(pkPsndoc);
            StaffAndOutStaff staffAndOutStaff = super.jdbcFindObject(sb.toString(), params, StaffAndOutStaff.class);
            if (staffAndOutStaff != null) {
                return staffAndOutStaff.getStaffName();
            }
        }
        return "";
    }

    @Override
    public PageInfo queryPageInfoBySmallContractUnit(SmallContractUnit smallContractUnit, int current, int pageSize) {
        //String orgName = PermissionUtil.getManagerOrg();
        StringBuilder sb = new StringBuilder(" SELECT * FROM VIEW_SMALLCONTRACTUNIT_LIST T WHERE 1 = 1 ");
        List<Object> params = new ArrayList<Object>();
        String code = PlatformUtil.getCurrentUser().getScreenName().toUpperCase();
		String orgName ="";
		//String[] orgnamelist= {"呼伦","兴安","通辽","赤峰","锡林","乌兰","乌海"};
		String[] orgnamelist=null;
		String orgNametemp =null;
		if(!StrUtil.isNullOrEmpty(code)) {
			orgNametemp = PermissionUtil.getManagerOrg();
			orgnamelist=orgNametemp.split(",");
			if(orgnamelist != null && orgnamelist.length==1) {
				orgName=orgnamelist[0];
			}
		}
        
        if (null != smallContractUnit) {
            if (!StrUtil.isNullOrEmpty(smallContractUnit.getName())) {
                sb.append(" AND T.name like ? ");
                params.add("%" + StringEscapeUtils.escapeSql(smallContractUnit.getName()) + "%");
            }
            if (!StrUtil.isNullOrEmpty(smallContractUnit.getCode())) {
                sb.append(" AND T.ode = ? ");
                params.add(smallContractUnit.getCode());
            }
            if (!StrUtil.isNullOrEmpty(smallContractUnit.getPkOrg())) {
                sb.append(" AND T.pkOrg = ? ");
                params.add(smallContractUnit.getPkOrg());
            }
            if (!StrUtil.isNullOrEmpty(smallContractUnit.getPkDept())) {
                sb.append(" AND T.pkDept = ? ");
                params.add(smallContractUnit.getPkDept());
            }
        }
       /* if (!"区本部".equals(orgName)) {
            sb.append(" AND T.orgName LIKE ? ");
            params.add("%" + StringEscapeUtils.escapeSql(orgName) + "%");
        }*/
        if (!"区本部".equals(orgName) && !StrUtil.isNullOrEmpty(orgName)) {
			sb.append(" AND T.ORGNAME LIKE ? ");
			params.add("%" + StringEscapeUtils.escapeSql(orgName) + "%");
		}
			if(orgnamelist !=null && orgnamelist.length>1) {
				sb.append("AND (T.orgName like ? ");
				params.add("%"+orgnamelist[0]+"%");
				for(int i=1;i<orgnamelist.length-1;i++) {
					sb.append(" OR T.orgName like ? ");
					params.add("%"+orgnamelist[i]+"%");
				}
				sb.append(" OR T.orgName like ? )");
				params.add("%"+orgnamelist[orgnamelist.length-1]+"%");
			}
			//用于查询13个组织下的全部人员
			if(!StrUtil.isNullOrEmpty(smallContractUnit.getOrgName())) {
			//为了查询带*号组织下的全部人员
			if(smallContractUnit.getOrgName().endsWith("*")) {
					sb.append(" AND T.orgName like ? ");
					params.add("%"+smallContractUnit.getOrgName().substring(0, 2)+"%");
        	}
        	else {
        		sb.append(" AND T.orgName = ? ");
        		params.add(smallContractUnit.getOrgName());
        	}
		}
			sb.append(" ORDER BY T.orgName");
        return this.jdbcFindPageInfo(sb.toString(), params, current, pageSize, SmallContractUnit.class);
    }

    @Override
    public List<Map<String, Object>> getSmallContractUnitData(SmallContractUnit smallContractUnit) {
        //String orgName = PermissionUtil.getManagerOrg();
        List<Object> params = new ArrayList<Object>();
        StringBuffer sb = new StringBuffer();
        String code = PlatformUtil.getCurrentUser().getScreenName().toUpperCase();
		String orgName ="";
		//String[] orgnamelist= {"呼伦","兴安","通辽","赤峰","锡林","乌兰","乌海"};
		String[] orgnamelist=null;
		String orgNametemp =null;
		if(!StrUtil.isNullOrEmpty(code)) {
			orgNametemp = PermissionUtil.getManagerOrg();
			orgnamelist=orgNametemp.split(",");
			if(orgnamelist != null && orgnamelist.length==1) {
				orgName=orgnamelist[0];
			}
		}
        sb.append(" SELECT T.proOrgName 上级公司名称,T.orgName 公司名称,T.deptCode 部门编码,T.deptName 部门名称, "
                + " T.deptLevelRelation 部门层级关系,T.isContractUnit 是否承包单元,T.contractUnitType 承包单元类型, "
                + " T.deptPrincipalCode 部门负责人编码,T.deptPrincipalName 部门负责人名称,T.code 人员编码,T.name 人员姓名, "
                + " T.personTypeCode 人员类别编码,T.personTypeName 人员类别名称,T.isCEO 是否小CEO,T.sex 性别, "
                + " T.isDismissContract 是否解除中止合同 , T.proOrgCode 上级公司编码,T.orgCode 公司编码  FROM   VIEW_SMALLCONTRACTUNIT_LIST T WHERE 1 = 1    ");
        if (null != smallContractUnit) {
            if (!StrUtil.isNullOrEmpty(smallContractUnit.getName())) {
                sb.append(" AND T.name like ? ");
                params.add("%" + StringEscapeUtils.escapeSql(smallContractUnit.getName()) + "%");
            }
            if (!StrUtil.isNullOrEmpty(smallContractUnit.getCode())) {
                sb.append(" AND T.code = ? ");
                params.add(smallContractUnit.getCode());
            }
            if (!StrUtil.isNullOrEmpty(smallContractUnit.getPkOrg())) {
                sb.append(" AND T.pkOrg = ? ");
                params.add(smallContractUnit.getPkOrg());
            }
            if (!StrUtil.isNullOrEmpty(smallContractUnit.getPkDept())) {
                sb.append(" AND T.pkDept = ? ");
                params.add(smallContractUnit.getPkDept());
            }
        }
       /* if (!"区本部".equals(orgName)) {
            sb.append(" AND T.orgName LIKE ? ");
            params.add("%" + StringEscapeUtils.escapeSql(orgName) + "%");
        }*/
        if (!"区本部".equals(orgName) && !StrUtil.isNullOrEmpty(orgName)) {
			sb.append(" AND T.ORGNAME LIKE ? ");
			params.add("%" + StringEscapeUtils.escapeSql(orgName) + "%");
		}
			if(orgnamelist !=null && orgnamelist.length>1) {
				sb.append("AND (T.orgName like ? ");
				params.add("%"+orgnamelist[0]+"%");
				for(int i=1;i<orgnamelist.length-1;i++) {
					sb.append(" OR T.orgName like ? ");
					params.add("%"+orgnamelist[i]+"%");
				}
				sb.append(" OR T.orgName like ? )");
				params.add("%"+orgnamelist[orgnamelist.length-1]+"%");
			}
			//用于查询13个组织下的全部人员
			if(!StrUtil.isNullOrEmpty(smallContractUnit.getOrgName())) {
			//为了查询带*号组织下的全部人员
			if(smallContractUnit.getOrgName().endsWith("*")) {
					sb.append(" AND T.orgName like ? ");
					params.add("%"+smallContractUnit.getOrgName().substring(0, 2)+"%");
        	}
        	else {
        		sb.append(" AND T.orgName = ? ");
        		params.add(smallContractUnit.getOrgName());
        	}
		}
			sb.append(" ORDER BY T.orgName");
        return this.getJdbcTemplate().queryForList(sb.toString(), params.toArray());
    }
/**
 * 人员信息总表查询
 */
    @Override
    public PageInfo queryPageInfoByStaffTotalInfo(StaffTotalInfo staffTotalInfo, int current, int pageSize) {
       // String orgName = PermissionUtil.getManagerOrg();
        StringBuilder sb = new StringBuilder(" SELECT * FROM  VIEW_STAFFTOTALINFO_LIST  T WHERE 1 = 1 ");
        List<Object> params = new ArrayList<Object>();
        String code = PlatformUtil.getCurrentUser().getScreenName().toUpperCase();
		String orgName ="";
		//String[] orgnamelist= {"呼伦","兴安","通辽","赤峰","锡林","乌兰","乌海"};
		String[] orgnamelist=null;
		String orgNametemp =null;
		if(!StrUtil.isNullOrEmpty(code)) {
			orgNametemp = PermissionUtil.getManagerOrg();
			orgnamelist=orgNametemp.split(",");
			if(orgnamelist != null && orgnamelist.length==1) {
				orgName=orgnamelist[0];
			}
		}
        if (null != staffTotalInfo) {
        	//这个是虚拟的人员，故直接写死，蒙通服三个人员
			/*String code = PlatformUtil.getCurrentUser().getScreenName().toUpperCase();
			int temp=0;//初始化
			String[] orgnamelist= {"呼伦","兴安","通辽","赤峰","锡林","乌兰","乌海"};
			if("W2019100".equals(code) || "W2019101".equals(code) || "W2019102".equals(code)) {
				temp=1;
			}*/
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getStaffName())) {
                sb.append(" AND T.staffName like ? ");
                params.add("%" + StringEscapeUtils.escapeSql(staffTotalInfo.getStaffName()) + "%");
            }
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getStaffCode())) {
                sb.append(" AND T.staffCode = ? ");
                params.add(staffTotalInfo.getStaffCode());
            }
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getPkOrg())) {
                sb.append(" AND T.pkOrg = ? ");
                params.add(staffTotalInfo.getPkOrg());
            }
            /*if(!StrUtil.isNullOrEmpty(staffTotalInfo.getOrgName())) {
            	if(temp==1) {
	            	for(int i=0;i<orgnamelist.length;i++) {
						if(staffTotalInfo.getOrgName().contains(orgnamelist[i])) {
							temp=2;
							break;
						}
					}
            	}
            	if(temp==0 || temp==2) {
            	if(staffTotalInfo.getOrgName().endsWith("*")) {
            		sb.append(" AND T.orgName like ? ");
            		params.add("%"+staffTotalInfo.getOrgName().substring(0, 2)+"%");
            	}
            	else {
            		sb.append(" AND T.orgName = ? ");
            		params.add(staffTotalInfo.getOrgName());
            	}
            }else {
        		sb.append(" AND 1=2 ");
        	}
           }*/
            
           /* if (!StrUtil.isNullOrEmpty(staffTotalInfo.getOrgName())) {
               sb.append(" AND T.orgName = ? ");
                params.add(staffTotalInfo.getOrgName());
            }*/
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getPkDept())) {
                sb.append(" AND T.pkDept = ? ");
                params.add(staffTotalInfo.getPkDept());
            }
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getDeptName())) {
                sb.append(" AND T.deptName = ? ");
                params.add(staffTotalInfo.getDeptName());
            }
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getUecBdPsnclList())) {
                List<UecBdPsncl> UecBdPsncls = staffTotalInfo.getUecBdPsnclList();
                String a = " AND T.staffType in ( ";
                String b = "";
                String c = ")";
                for (UecBdPsncl uecBdPsncl : UecBdPsncls) {
                    String name = uecBdPsncl.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getEndPostionDate())) {
                sb.append(" AND (T.endPostionDate <= ? OR T.endPostionDate is null) ");
                params.add(staffTotalInfo.getEndPostionDate());
            }
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getNewPostGradeList())
                    && staffTotalInfo.getNewPostGradeList().size() > 0) {
                List<UecBdDefdoc> uecBddefdocs = staffTotalInfo.getNewPostGradeList();
                String a = "AND T.postlevel in ( ";
                String b = "";
                String c = ")";
                for (UecBdDefdoc uecBdDefdoc : uecBddefdocs) {
                    String name = uecBdDefdoc.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getOldPostGradeList())
                    && staffTotalInfo.getOldPostGradeList().size() > 0) {
                List<UecBdDefdoc> uecBddefdocs = staffTotalInfo.getOldPostGradeList();
                String a = "AND T.postlevel in ( ";
                String b = "";
                String c = ")";
                for (UecBdDefdoc uecBdDefdoc : uecBddefdocs) {
                    String name = uecBdDefdoc.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getPostGradeList())) {
                List<UecBdDefdoc> uecBddefdocs = staffTotalInfo.getPostGradeList();
                String a = "AND T.postgrade in ( ";
                String b = "";
                String c = ")";
                for (UecBdDefdoc uecBdDefdoc : uecBddefdocs) {
                    String name = uecBdDefdoc.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
     
        }
        /*if (!"区本部".equals(orgName)) {
            sb.append(" AND T.orgName LIKE ? ");
            params.add("%" + StringEscapeUtils.escapeSql(orgName) + "%");
        }*/
        if (!"区本部".equals(orgName) && !StrUtil.isNullOrEmpty(orgName)) {
			sb.append(" AND T.ORGNAME LIKE ? ");
			params.add("%" + StringEscapeUtils.escapeSql(orgName) + "%");
		}
			if(orgnamelist !=null && orgnamelist.length>1) {
				sb.append("AND (T.orgName like ? ");
				params.add("%"+orgnamelist[0]+"%");
				for(int i=1;i<orgnamelist.length-1;i++) {
					sb.append(" OR T.orgName like ? ");
					params.add("%"+orgnamelist[i]+"%");
				}
				sb.append(" OR T.orgName like ? )");
				params.add("%"+orgnamelist[orgnamelist.length-1]+"%");
			}
			//用于查询13个组织下的全部人员
			if(!StrUtil.isNullOrEmpty(staffTotalInfo.getOrgName())) {
			//为了查询带*号组织下的全部人员
			if(staffTotalInfo.getOrgName().endsWith("*")) {
					sb.append(" AND T.orgName like ? ");
					params.add("%"+staffTotalInfo.getOrgName().substring(0, 2)+"%");
        	}
        	else {
        		sb.append(" AND T.orgName = ? ");
        		params.add(staffTotalInfo.getOrgName());
        	}
		}
			sb.append(" ORDER BY T.orgName");
        return this.jdbcFindPageInfo(sb.toString(), params, current, pageSize, StaffTotalInfo.class);
    }
	/**
	 * 人员总表下载数据
	 */
    @Override
    public List<Map<String, Object>> getStaffTotalInfoData(StaffTotalInfo staffTotalInfo) {
       // String orgName = PermissionUtil.getManagerOrg();
        List<Object> params = new ArrayList<Object>();
        StringBuffer sb = new StringBuffer();
        sb.append(" SELECT * FROM  V_VIEW_STAFFTOTALINFO_LIST T WHERE 1 = 1    ");
        String code = PlatformUtil.getCurrentUser().getScreenName().toUpperCase();
		String orgName ="";
		//String[] orgnamelist= {"呼伦","兴安","通辽","赤峰","锡林","乌兰","乌海"};
		String[] orgnamelist=null;
		String orgNametemp =null;
		if(!StrUtil.isNullOrEmpty(code)) {
			orgNametemp = PermissionUtil.getManagerOrg();
			orgnamelist=orgNametemp.split(",");
			if(orgnamelist != null && orgnamelist.length==1) {
				orgName=orgnamelist[0];
			}
		}
        if (null != staffTotalInfo) {
        	//这个是虚拟的人员，故直接写死，蒙通服三个人员
			/*String code = PlatformUtil.getCurrentUser().getScreenName().toUpperCase();
			int temp=0;//初始化
			String[] orgnamelist= {"呼伦","兴安","通辽","赤峰","锡林","乌兰","乌海"};
			if("W2019100".equals(code) || "W2019101".equals(code) || "W2019102".equals(code)) {
				temp=1;
			}*/
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getStaffName())) {
                sb.append(" AND t.姓名 like ? ");
                params.add("%" + StringEscapeUtils.escapeSql(staffTotalInfo.getStaffName()) + "%");
            }
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getStaffCode())) {
                sb.append(" AND t. 人员编码 = ? ");
                params.add(staffTotalInfo.getStaffCode());
            }
            /*if (!StrUtil.isNullOrEmpty(staffTotalInfo.getOrgName())) {
                sb.append(" AND T.公司名称 = ? ");
                params.add(staffTotalInfo.getOrgName());
            }*/
           
            /*if(!StrUtil.isNullOrEmpty(staffTotalInfo.getOrgName())) {
            	if(temp==1) {
	            	for(int i=0;i<orgnamelist.length;i++) {
						if(staffTotalInfo.getOrgName().contains(orgnamelist[i])) {
							temp=2;
							break;
						}
					}
            	}
            	if(temp==0 || temp==2) {
            	if(staffTotalInfo.getOrgName().endsWith("*")) {
            		sb.append(" AND T.公司名称 like ? ");
            		params.add("%"+staffTotalInfo.getOrgName().substring(0, 2)+"%");
            	}
            	else {
            		sb.append(" AND T.公司名称 = ? ");
            		params.add(staffTotalInfo.getOrgName());
            	}
            }else {
        		sb.append(" AND 1=2 ");
        	}
           }*/
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getDeptName())) {
                sb.append(" AND T.部门名称 = ? ");
                params.add(staffTotalInfo.getDeptName());
            }
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getUecBdPsnclList())) {
                List<UecBdPsncl> UecBdPsncls = staffTotalInfo.getUecBdPsnclList();
                String a = " AND T.人员类别  in ( ";
                String b = "";
                String c = ")";
                for (UecBdPsncl uecBdPsncl : UecBdPsncls) {
                    String name = uecBdPsncl.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getEndPostionDate())) {
                sb.append(" AND (T.任职结束时间 <= ? or T.任职结束时间 is null) ");
                params.add(staffTotalInfo.getEndPostionDate());
            }
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getNewPostGradeList())
                    && staffTotalInfo.getNewPostGradeList().size() > 0) {
                List<UecBdDefdoc> uecBddefdocs = staffTotalInfo.getNewPostGradeList();
                String a = "AND T.岗位层级 in ( ";
                String b = "";
                String c = ")";
                for (UecBdDefdoc uecBdDefdoc : uecBddefdocs) {
                    String name = uecBdDefdoc.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getOldPostGradeList())
                    && staffTotalInfo.getOldPostGradeList().size() > 0) {
                List<UecBdDefdoc> uecBddefdocs = staffTotalInfo.getOldPostGradeList();
                String a = "AND T.岗位层级 in ( ";
                String b = "";
                String c = ")";
                for (UecBdDefdoc uecBdDefdoc : uecBddefdocs) {
                    String name = uecBdDefdoc.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
            if (!StrUtil.isNullOrEmpty(staffTotalInfo.getPostGradeList())) {
                List<UecBdDefdoc> uecBddefdocs = staffTotalInfo.getPostGradeList();
                String a = "AND T.岗位等级 in ( ";
                String b = "";
                String c = ")";
                for (UecBdDefdoc uecBdDefdoc : uecBddefdocs) {
                    String name = uecBdDefdoc.getName();
                    params.add(name);
                    b = b + "?" + ",";
                }
                b = b.substring(0, b.length() - 1);
                String sql = a + b + c;
                sb.append(sql);
            }
     
            
        }
       /* if (!"区本部".equals(orgName)) {
            sb.append(" AND T.公司名称 LIKE ? ");
            params.add("%" + StringEscapeUtils.escapeSql(orgName) + "%");
        }*/
        if (!"区本部".equals(orgName) && !StrUtil.isNullOrEmpty(orgName)) {
			sb.append(" AND T.公司名称 LIKE ? ");
			params.add("%" + StringEscapeUtils.escapeSql(orgName) + "%");
		}
			if(orgnamelist !=null && orgnamelist.length>1) {
				sb.append("AND (T.公司名称 like ? ");
				params.add("%"+orgnamelist[0]+"%");
				for(int i=1;i<orgnamelist.length-1;i++) {
					sb.append(" OR T.公司名称 like ? ");
					params.add("%"+orgnamelist[i]+"%");
				}
				sb.append(" OR T.公司名称 like ? )");
				params.add("%"+orgnamelist[orgnamelist.length-1]+"%");
			}
			//用于查询13个组织下的全部人员
			if(!StrUtil.isNullOrEmpty(staffTotalInfo.getOrgName())) {
			//为了查询带*号组织下的全部人员
			if(staffTotalInfo.getOrgName().endsWith("*")) {
					sb.append(" AND T.公司名称 like ? ");
					params.add("%"+staffTotalInfo.getOrgName().substring(0, 2)+"%");
        	}
        	else {
        		sb.append(" AND T.公司名称 = ? ");
        		params.add(staffTotalInfo.getOrgName());
        	}
		}
			sb.append(" ORDER BY T.公司名称");
        return this.getJdbcTemplate().queryForList(sb.toString(), params.toArray());
    }

   
}
